﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using IllSoft.Xvcc.Volano.Client;

namespace IllSoft.Xvcc.UI
{
    public partial class ChannelForm : Form
    {
        private Channel _channel;

        public ChannelForm()
        {
            InitializeComponent();
        }

        public ChannelForm(Channel channel) : this()
        {
            this._channel = channel;

            this._channel.Message += new EventHandler<MessageEventArgs>(_channel_Message);

            this._channel.Join();
        }

        void _channel_Message(object sender, MessageEventArgs e)
        {
            if (this.InvokeRequired)
            {
                this.Invoke((Action<string>)this.messagesRichTextBox.AppendText, e.User.Nick + ": " + e.Message + Environment.NewLine);
            }
            else
            {
                this.messagesRichTextBox.AppendText(e.User.Nick + ": " + e.Message + Environment.NewLine);
            }
        }

        private void ChannelForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            this._channel.Part();
        }
    }
}
